home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / test / test3.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  2KB  |  96 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #ifdef __sgi
  9. #include <malloc.h>
  10. #endif
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <GL/glut.h>
  14. #include <glutint.h>
  15.  
  16. #define N 6
  17. #define M 6
  18.  
  19. int exposed[M * N];
  20. int ecount = 0;
  21. int viewable[M * N];
  22. int vcount = 0;
  23.  
  24. void
  25. display(void)
  26. {
  27.   int win;
  28.  
  29.   win = glutGetWindow() - 1;
  30.   if (!exposed[win]) {
  31.     exposed[win] = 1;
  32.     ecount++;
  33.   }
  34.   glClear(GL_COLOR_BUFFER_BIT);
  35.   if ((ecount == (M * N)) && (vcount == (M * N))) {
  36.     printf("PASS: test3\n");
  37.     exit(0);
  38.   }
  39. }
  40.  
  41. void
  42. view(int state)
  43. {
  44.   int win;
  45.  
  46.   win = glutGetWindow() - 1;
  47.   if (!viewable[win]) {
  48.     viewable[win] = 1;
  49.     vcount++;
  50.   }
  51.   if ((ecount == (M * N)) && (vcount == (M * N))) {
  52.     printf("PASS: test3\n");
  53.     exit(0);
  54.   }
  55. }
  56.  
  57. void
  58. timer(int value)
  59. {
  60.   if (value != 23)
  61.     __glutFatalError("FAIL: bad timer value");
  62.   __glutFatalError("FAIL: didn't get all expose and viewable calls in 10 seconds");
  63. }
  64.  
  65. int
  66. main(int argc, char **argv)
  67. {
  68.   char buf[100];
  69.   int i, j;
  70.  
  71. #if defined(__sgi)  && !defined(REDWOOD)
  72.   /* XXX IRIX 6.0.1 mallopt(M_DEBUG, 1) busted. */
  73.   mallopt(M_DEBUG, 1);
  74. #endif
  75.   glutInit(&argc, argv);
  76.   glutInitWindowSize(10, 10);
  77.   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  78.   for (i = 0; i < M; i++) {
  79.     for (j = 0; j < N; j++) {
  80.       exposed[i * N + j] = 0;
  81.       viewable[i * N + j] = 0;
  82.       glutInitWindowPosition(100 * i, 100 * j);
  83.       sprintf(buf, "%d\n", i * N + j + 1);
  84.       glutCreateWindow(buf);
  85.       glutDisplayFunc(display);
  86.       glutVisibilityFunc(view);
  87.       glClearColor(1.0, 0.0, 0.0, 1.0);
  88.     }
  89.   }
  90.   /* XXX Hopefully in 45 seconds, all the windows should
  91.      appear, or they probably won't ever appear! */
  92.   glutTimerFunc(45 * 1000, timer, 23);
  93.   glutMainLoop();
  94.   return 0;             /* ANSI C requires main to return int. */
  95. }
  96.